package com.ruoyi.rsikManage.service.Impl;

import java.util.List;

import com.ruoyi.common.core.page.PageParam;
import com.ruoyi.electricity.domain.CoalMineInfo;
import com.ruoyi.electricity.mapper.CoalMineInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.rsikManage.domain.TAlgoScenario;
import com.ruoyi.rsikManage.mapper.TAlgoScenarioMapper;
import com.ruoyi.rsikManage.service.ITAlgoScenarioService;

/**
 * 算法场景描述Service业务层处理
 *
 * @author sxygsj
 * @date 2024-05-06
 */
@Service
public class TAlgoScenarioServiceImpl implements ITAlgoScenarioService
{
    @Autowired
    private TAlgoScenarioMapper tAlgoScenarioMapper;

    @Autowired
    private CoalMineInfoMapper coalMineInfoMapper;
    /**
     * 查询算法场景描述
     *
     * @param id 算法场景描述主键
     * @return 算法场景描述
     */
    @Override
    public TAlgoScenario selectTAlgoScenarioById(Long id)
    {
        return tAlgoScenarioMapper.selectTAlgoScenarioById(id);
    }

    /**
     * 查询算法场景描述列表
     *
     * @param tAlgoScenario 算法场景描述
     * @return 算法场景描述
     */
    @Override
    public List<TAlgoScenario> selectTAlgoScenarioList(TAlgoScenario tAlgoScenario)
    {

        tAlgoScenario.setUnitCode(getUnitCode());
        return tAlgoScenarioMapper.selectTAlgoScenarioList(tAlgoScenario);
    }

    /**
     * 新增算法场景描述
     *
     * @param tAlgoScenario 算法场景描述
     * @return 结果
     */
    @Override
    public int insertTAlgoScenario(TAlgoScenario tAlgoScenario)
    {

        tAlgoScenario.setUnitCode(getUnitCode());
        return tAlgoScenarioMapper.insertTAlgoScenario(tAlgoScenario);
    }

    @Override
    public int insertTAlgoScenarioV2(TAlgoScenario tAlgoScenario) {
        return 0;
    }

    /**
     * 修改算法场景描述
     *
     * @param tAlgoScenario 算法场景描述
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTAlgoScenario(TAlgoScenario tAlgoScenario)
    {
        tAlgoScenario.setUnitCode(getUnitCode());
        return tAlgoScenarioMapper.updateTAlgoScenario(tAlgoScenario);
    }

    /**
     * 批量删除算法场景描述
     *
     * @param ids 需要删除的算法场景描述主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTAlgoScenarioByIds(Long[] ids)
    {
        return tAlgoScenarioMapper.deleteTAlgoScenarioByIds(ids);
    }

    /**
     * 删除算法场景描述信息
     *
     * @param id 算法场景描述主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTAlgoScenarioById(Long id)
    {
        tAlgoScenarioMapper.deleteTAlgoScenarioBy(id);
        return tAlgoScenarioMapper.deleteTAlgoScenarioById(id);
    }

    @Override
    public List<TAlgoScenario> selectdetailsList(TAlgoScenario tAlgoScenario, PageParam pageParam) {

        return tAlgoScenarioMapper.selectdetailsList(tAlgoScenario,pageParam);
    }

    @Override
    public int  countAlgoScenarios(TAlgoScenario tAlgoScenario) {

        return tAlgoScenarioMapper.countAlgoScenarios(tAlgoScenario);
    }
    //公共方法获取 煤矿编码
    public String  getUnitCode() {
        //根据煤矿基础信息获取煤矿编码
        CoalMineInfo coalMineInfo = new CoalMineInfo();
        coalMineInfo.setItem("煤矿编码");
        coalMineInfo.setConfigurationType("煤矿基础信息");
        List<CoalMineInfo> coalMineInfos = coalMineInfoMapper.selectCoalMineInfoList(coalMineInfo);
        String unitCode = coalMineInfos.get(0).getValue();
        return unitCode;
    }

}
